package tests;

import org.apache.log4j.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class AssetsTest extends RunnableClerkTest {

	@Before
	public void setUp() throws Exception {
		super.setUp();
		this.fLogger = Logger.getLogger(AssetsTest.class);
	}

	@After
	public void tearDown() throws Exception {
	}

	/*	@Test
		public void testAssets() {
			 Pattern regex = Pattern.compile("\\[main:INFO\\]\\s+reit\\.main\\.Parser:\\s+creating\\s+AssetContent\\s+with:\\s+name:Fridge\\s+RepairMultiplier:1\\.5");
			 boolean isDataLogged = LoggerTool.isInLog(regex);
			 assertTrue(isDataLogged);
		}

		@Test
		public void testTakeAsset() {
			RentalRequest failingAssetType = new RentalRequest((byte)0xe0, "failureAssetType", (byte)0x20, (byte)0x40);
			assertTrue(null == this.fAssets.take(failingAssetType));
			
			RentalRequest failingAssetType2 = new RentalRequest((byte)0xe0, "Apartment", (byte)0x79, (byte)0x99);
			assertTrue(null == this.fAssets.take(failingAssetType2));
			RentalRequest RR=null;
			Asset ret=null;
			try {
				 RR = fRentalRequests.take();
				 ret = this.fAssets.take(RR);			
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			assertTrue(ret!=null);
		}

		@Test
		public void testReturnAsset() {
			RentalRequest RR=null;
			Asset ret=null;
			try {
				 RR = fRentalRequests.take();
				 ret = this.fAssets.take(RR);	
				 int mySize = this.fAssets.size();
				 this.fAssets.add(ret);
				 assertTrue(mySize < this.fAssets.size());
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}*/
	@Test
	public void testCuncerrancy() {
		this.fManagement.startSim();

		/*
		fLogger.info("testing "+this.fRentalRequests.size()+" rental Requests");
		for (int i=0;i<this.fRunnableClerks.size();i++){
		//	this.fRunnableClerks.get(i).start();
		}

		try {
			Thread.sleep(200);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		Pattern regexShouldFind = Pattern.compile("\\[clerk_\\d+:INFO\\]\\s+reit\\.main\\.RunnableClerk:\\s+searching\\s+for\\s+asset\\s+for\\s+request\\s+6");
		Pattern regexShouldNotFind = Pattern.compile("\\[clerk_\\d+:INFO\\]\\s+reit\\.main\\.RunnableClerk:\\s+found\\s+room\\s+Asset\\s+\\d+\\s+for\\s+rental\\s+request\\s+6");
		
		assertTrue(LoggerTool.isInLog(regexShouldFind) && !LoggerTool.isInLog(regexShouldNotFind));*/

	}

}
